package com.xutianpeng.disk.spring.util;

import org.jasypt.util.text.BasicTextEncryptor;

public final class JasyptUtil {
    private JasyptUtil(){}

        private static final String textKey = "0123456789ABCDEF";
        public static String decrypt(String password){
            BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
            textEncryptor.setPassword(textKey);
            return  textEncryptor.decrypt(password);

        }

        public static String encrypt(String password){
            BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
            textEncryptor.setPassword(textKey);
            return textEncryptor.encrypt(password);
        }

        public static void main(String[] args) {
            for (String item:args){
                System.out.print(item + " ");
            }
            System.out.println();
            if(args.length > 1){
                if("2".equals(args[0])){
                    System.out.println(decrypt(args[1]));
                }else{
                    System.out.println(encrypt(args[1]));
                }
            }else{
                System.out.println("<operation> <password> \n operation:\n 1:encrypt 2:decrypt");
            }
        }

}
